package com.xydtech.ecard.ecard.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xydtech.common.EcardOrgInfoApiCommon;
import com.xydtech.common.annotation.RsaRequest;
import com.xydtech.common.core.domain.entity.SysDept;
import com.xydtech.common.enums.ResultStatus;
import com.xydtech.common.model.ResponseModel;
import com.xydtech.common.utils.DateUtils;
import com.xydtech.common.utils.GeoUtil;
import com.xydtech.common.utils.StringUtils;
import com.xydtech.ecard.config.service.IEcardApiSysConfigService;
import com.xydtech.ecard.ecard.domain.*;
import com.xydtech.ecard.ecard.service.*;
import com.xydtech.ecard.merchant.domain.*;
import com.xydtech.ecard.merchant.service.IEcardBranchEnterpriseChartService;
import com.xydtech.ecard.user.domain.EcardApiEcardRegistInfo;
import com.xydtech.ecard.user.domain.EcardApiUserInfo;
import com.xydtech.ecard.user.service.IEcardApiEcardRegistInfoService;
import com.xydtech.ecard.user.service.IEcardApiUserService;
import com.xydtech.system.domain.SysConfig;
import com.xydtech.system.domain.SysWechatApplet;
import com.xydtech.system.service.ISysConfigService;
import com.xydtech.system.service.ISysDeptService;
import com.xydtech.system.service.ISysUserService;
import com.xydtech.system.service.ISysWechatAppletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 电子名片-企业营销接口类
 *
 * @author yuzhiguo
 * @date 2024-07-18 下午1:52
 */

@Controller
@Slf4j
@Api(tags = "电子名片-企业营销接口")
@RequestMapping("/ecardSaasApi/enterpriseMarketing")
public class EcardEnterpriseMarketingController extends EcardApiBaseController {

    //4:客户经理
    private static String roles = "4";
    //客户经理岗位，后台没维护，这里用不到
    private static String cm = "cm";
    //网格管理员岗位
    private static String wg = "wg";

    @Autowired
    private IEcardApiUserService ecardApiUserService;
    @Autowired
    private IEcardApiEnterpriseInfoService ecardEnterpriseInfoService;
    @Autowired
    private IEcardApiEcardRegistInfoService registInfoService;
    @Autowired
    private IEcardApiMerchantVisitInfoService ecardMerchantVisitInfoService;
    @Autowired
    private ISysWechatAppletService wechatAppletService;
    @Autowired
    private IEcardApiSysConfigService ecardApiSysConfigService;
    @Autowired
    private IEcardApiMerchantTaskService ecardApiMerchantTaskService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private EcardOrgInfoApiCommon ecardOrgInfoApiCommon;
    @Autowired
    private IEcardApiEnterpriseLocationService enterpriseLocationService;
    @Autowired
    private IEcardApiMerchantPartInfoService ecardMerchantPartInfoService;
    @Autowired
    private ISysDeptService sysDeptService;
    @Autowired
    private ISysConfigService configService;
    @Autowired
    private IEcardApiEnterpriseTycService ecardEnterpriseTycService;
    @Autowired
    private IEcardBranchEnterpriseChartService ecardBranchEnterpriseChartService;
    @Autowired
    private ISysConfigService sysConfigService;

    /**
     * 电子名片-条件查询登录人名下企业列表接口
     *
     * @author yuzhiguo
     * @date 2024/7/18 下午1:56
     */
    @PostMapping(value = "/getMyEnterpriseList")
    @ApiOperation(value = "电子名片-条件查询登录人名下企业列表接口", notes = "电子名片-条件查询登录人名下企业列表接口")
    @ResponseBody
    @RsaRequest
    public ResponseModel getMyEnterpriseList(@RequestBody String json) {
        log.info("接口请求时间-------" + DateUtils.getTime());
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
            //当前小程序id
            SysWechatApplet wechatApplet = getAppIdByDeptId(userInfo.getDeptId());

            JSONObject jsonObject = JSONObject.parseObject(json);
            String search = jsonObject.getString("search");//查询条件姓名和手机号拆开（企业名称/联系人姓名）
            String phone = jsonObject.getString("phone");
            Integer industry = jsonObject.getInteger("industry");//所属行业
            Integer entLocationId = jsonObject.getInteger("entLocationId");//楼宇id
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");

            EcardApiEnterpriseInfo ecardEnterpriseInfo = new EcardApiEnterpriseInfo();
            ecardEnterpriseInfo.setEntName(search);
            ecardEnterpriseInfo.setContactsPhone(phone);
            ecardEnterpriseInfo.setEntIndustry(industry);
            ecardEnterpriseInfo.setManagementPersonnelId(Long.valueOf(currentUserId));
            ecardEnterpriseInfo.setEntLocationId(entLocationId);
            ecardEnterpriseInfo.setDictDeptId(wechatApplet.getDeptId());
            PageHelper.startPage(pageNum, pageSize);
            List<EcardApiEnterpriseInfo> enterpriseList = ecardEnterpriseInfoService.getMyEnterpriseList(ecardEnterpriseInfo, salt);
            List<EcardApiEnterpriseInfo> apiEnterpriseList = new ArrayList<>();
            PageInfo pageInfo = new PageInfo(enterpriseList);
            for (EcardApiEnterpriseInfo enterprise : enterpriseList) {
                //查询总拜访次数
                EcardApiMerchantVisitInfo merchantVisitInfo = new EcardApiMerchantVisitInfo();
                merchantVisitInfo.setMerchantId(enterprise.getId());
                merchantVisitInfo.setMerchantType("3");//商户类型：1-个人，2-商户，3-企业，4-新型农业主体
                List<EcardApiMerchantVisitInfo> visitInfoList = ecardMerchantVisitInfoService.getMerchantVisitList(merchantVisitInfo);
                enterprise.setVisitNumber(visitInfoList.size() + "");

                //查询最近一次拜访时间
                String lastVisitTime = ecardMerchantVisitInfoService.getMerchantLastVisitTime(enterprise.getId(), "3");//商户类型：1-个人，2-商户，3-企业，4-新型农业主体
                if (StringUtils.isNotEmpty(lastVisitTime)) {
                    enterprise.setLastVisitDate(DateUtils.parseDate(lastVisitTime));
                }
                apiEnterpriseList.add(enterprise);
            }
            log.info("接口返回时间-------" + DateUtils.getTime());
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), apiEnterpriseList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 电子名片-条件查询企业列表接口
     *
     * @param: type 1登录人所在机构下全部，2法人机构下全部（针对网格管理岗位）
     * @param: search 查询条件
     * @author yuzhiguo
     * @date 2024/7/22 8:44
     */
    @PostMapping(value = "/getEnterpriseList")
    @ApiOperation(value = "电子名片-条件查询企业列表接口", notes = "电子名片-条件查询企业列表接口")
    @ResponseBody
    @RsaRequest
    public ResponseModel getEnterpriseList(@RequestBody String json) {
        log.info("接口请求时间-------" + DateUtils.getTime());
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            //查询客户经理信息
            EcardApiEcardRegistInfo ecardApiEcardRegistInfo = registInfoService.selectEcardApiEcardRegistInfoByRegistId(Long.valueOf(currentUserId), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            String type = jsonObject.getString("type");
            String search = jsonObject.getString("search");//查询条件姓名和手机号拆开
            Integer industry = jsonObject.getInteger("industry");
            String sortTime = jsonObject.getString("sortTime");
            Integer entLocationId = jsonObject.getInteger("entLocationId");//楼宇id
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");

            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
            EcardApiEnterpriseInfo ecardEnterpriseInfo = new EcardApiEnterpriseInfo();
            ecardEnterpriseInfo.setEntName(search);
            ecardEnterpriseInfo.setEntIndustry(industry);
            ecardEnterpriseInfo.setSortTime(sortTime);
            ecardEnterpriseInfo.setEntLocationId(entLocationId);

            //当前小程序id
            SysWechatApplet wechatApplet = getAppIdByDeptId(userInfo.getDeptId());
            ecardEnterpriseInfo.setDictDeptId(wechatApplet.getDeptId());
            if (ecardApiEcardRegistInfo != null) {
                boolean postFlag = false;
                //多个岗位判断，只要有网格管理就传法人机构
                if (!StringUtils.objIsNullOrEmpty(userInfo.getExtendPostCode())) {
                    for (String extendPost : userInfo.getExtendPostCode().split(",")) {
                        if (wg.equals(extendPost)) {
                            postFlag = true;
                        }
                    }
                }
                if (roles.equals(ecardApiEcardRegistInfo.getRoles())) {
                    if ("1".equals(type) && !postFlag) {
                        ecardEnterpriseInfo.setDeptId(userInfo.getDeptId());
                    } else if (postFlag) {
                        ecardEnterpriseInfo.setDeptId(wechatApplet.getDeptId());
                    } else {
                        return ResponseModel.error("操作人岗位不正确,请联系管理员！");
                    }
                } else {
                    return ResponseModel.error("您没有查看企业列表的权限！");
                }
            } else {
                return ResponseModel.error("用户信息不存在！");
            }
            PageHelper.startPage(pageNum, pageSize);
            List<EcardApiEnterpriseInfo> enterpriseList = ecardEnterpriseInfoService.getEnterpriseList(ecardEnterpriseInfo);
            PageInfo pageInfo = new PageInfo(enterpriseList);
            log.info("接口返回时间-------" + DateUtils.getTime());
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), enterpriseList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 电子名片-查询企业地图坐标列表接口
     *
     * @param: type 1登录人所在机构下全部，2法人机构下全部（针对网格管理岗位）
     * @author yuzhiguo
     * @date 2024/7/22 9:05
     */
    @PostMapping(value = "/getEnterpriseCoordinateList")
    @ApiOperation(value = "电子名片-查询企业地图坐标列表接口", notes = "电子名片-查询企业地图坐标列表接口")
    @ResponseBody
    @RsaRequest
    public ResponseModel getEnterpriseCoordinateList(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            JSONObject jsonObject = JSONObject.parseObject(json);
            String type = jsonObject.getString("type");
            Integer industry = jsonObject.getInteger("industry");
            String coordinate = jsonObject.getString("coordinate");

            SysConfig config = new SysConfig();
            config.setConfigKey("ecard_merchant_show_distance");
            SysConfig sysConfig;

            if (StringUtils.objIsNullOrEmpty(currentUserId) || StringUtils.objIsNullOrEmpty(type)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            List<EcardApiEnterpriseInfo> enterpriseInfoList;
            //改为只查独立厂区的企业坐标列表
            if ("1".equals(type)) {
                //获取当前用户的信息
                EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
                enterpriseInfoList = ecardEnterpriseInfoService.getEnterpriseCoordinateList(Long.valueOf(currentUserId), userInfo.getDeptId(), industry, "2");
                SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
                config.setDeptId(sysDept.getDeptId());
                sysConfig = ecardApiSysConfigService.selectConfig(config);
            } else {
                EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
                //当前小程序id
                SysWechatApplet wechatApplet = getAppIdByDeptId(userInfo.getDeptId());
                enterpriseInfoList = ecardEnterpriseInfoService.getAllEnterpriseCoordinateList(Long.valueOf(currentUserId), wechatApplet.getDeptId(), industry, "2");
                SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(wechatApplet.getDeptId());
                config.setDeptId(sysDept.getDeptId());
                sysConfig = ecardApiSysConfigService.selectConfig(config);
            }

            //有经纬度就计算，没有取全部
            if (coordinate != null) {
                List<EcardApiEnterpriseInfo> list = new ArrayList<>();
                //计算是否在配置的范围之内
                //定位的企业经纬度
                String place[] = coordinate.split(",");
                for (EcardApiEnterpriseInfo ecardApiEnterpriseInfo : enterpriseInfoList) {
                    String clockInPlace[] = ecardApiEnterpriseInfo.getEntCoordinate().split(",");
                    Double distance = GeoUtil.GetDistance(Double.valueOf(clockInPlace[1]), Double.valueOf(clockInPlace[0]), Double.valueOf(place[1]), Double.valueOf(place[0]));

                    BigDecimal bigDistance = new BigDecimal(distance);
                    BigDecimal bigValue = new BigDecimal(sysConfig.getConfigValue());
                    if (bigDistance.compareTo(bigValue) <= 0) {
                        list.add(ecardApiEnterpriseInfo);
                    }
                }
                return ResponseModel.okToJSONArray(list);
            } else {
                return ResponseModel.okToJSONArray(enterpriseInfoList);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 电子名片-查询企业详情接口
     *
     * @author yuzhiguo
     * @date 2024/7/22 9:33
     */
    @PostMapping("/getEnterpriseInfo")
    @ApiOperation(value = "电子名片-查询企业详情接口", notes = "电子名片-查询企业详情接口")
    @ResponseBody
    @RsaRequest
    public ResponseModel getEnterpriseInfo(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            EcardApiEcardRegistInfo ecardApiEcardRegistInfo = registInfoService.selectEcardApiEcardRegistInfoByRegistId(Long.valueOf(currentUserId), salt);
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);

            if (!roles.equals(ecardApiEcardRegistInfo.getRoles())) {
                return ResponseModel.error("您没有查看该企业的权限！");
            }

            JSONObject jsonObject = JSONObject.parseObject(json);
            Long id = jsonObject.getLong("id");
            if (StringUtils.objIsNullOrEmpty(id)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            //根据企业id查询企业成员信息
            EcardApiMerchantPartInfo apiMerchantPartInfo = new EcardApiMerchantPartInfo();
            apiMerchantPartInfo.setMerchantId(id);
            apiMerchantPartInfo.setMerchantType("3");
            List<EcardApiMerchantPartInfo> merchantPartList = ecardMerchantPartInfoService.selectEcardMerchantPartInfoList(apiMerchantPartInfo, salt);//商户类型：1-个人，2-商户，3-企业，4-新型农业主体
//            if (wg.equals(userInfo.getExtendPostCode())) {
            EcardApiEnterpriseInfo enterpriseInfo = ecardEnterpriseInfoService.selectEcardEnterpriseInfoById(id, salt);
            if (merchantPartList.size() > 0) {
                enterpriseInfo.setEcardApiMerchantPartInfos(merchantPartList);
            }
            return ResponseModel.okToJSON(enterpriseInfo);

          /*  } else {
                EcardApiEnterpriseInfo enterpriseInfo = ecardEnterpriseInfoService.selectEcardEnterpriseInfoByIdAndCreatorId(id, ecardApiEcardRegistInfo.getRegistId());
                enterpriseInfo.setEcardApiMerchantPartInfos(merchantPartList);
                return ResponseModel.okToJSON(enterpriseInfo);
            }*/
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 电子名片-保存企业数据接口,只有客户经理能保存企业信息
     *
     * @author yuzhiguo
     * @date 2024/7/18 下午3:43
     */
    @PostMapping(value = "/addEnterpriseInfo")
    @ApiOperation(value = "电子名片-保存企业数据接口", notes = "电子名片-保存企业数据接口")
    @ResponseBody
    @RsaRequest(result = false)
    public ResponseModel addEnterpriseInfo(@RequestBody EcardApiEnterpriseInfo ecardEnterpriseInfo) {
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            Long entId = ecardEnterpriseInfo.getId();//企业id
            boolean flag = false;//判断是新增还是编辑，true：新增，false：编辑
            EcardApiEcardRegistInfo ecardApiEcardRegistInfo = registInfoService.selectEcardApiEcardRegistInfoByRegistId(Long.valueOf(currentUserId), salt);
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
            if (!roles.equals(ecardApiEcardRegistInfo.getRoles())) {
                return ResponseModel.error("您没有编辑企业信息的权限！");
            }
            //当前小程序id
            SysWechatApplet wechatApplet = getAppIdByDeptId(userInfo.getDeptId());

            //当前登录人ID
            ecardEnterpriseInfo.setCreatorId(Long.valueOf(currentUserId));
            //管户人id
            ecardEnterpriseInfo.setManagementPersonnelId(Long.valueOf(currentUserId));
            //登录人机构ID
            ecardEnterpriseInfo.setDeptId(userInfo.getDeptId());
            if (!StringUtils.isNotNull(ecardEnterpriseInfo.getId())) {
                int count = ecardEnterpriseInfoService.validateEnterpriseInfo(ecardEnterpriseInfo);
                if (count > 0) {
                    return ResponseModel.error("相同行业、支行、企业名不能重复！");
                }
                flag = true;
            } else {
                //校验是否是自己的企业
                EcardApiEnterpriseInfo ecardApiEnterpriseInfo = ecardEnterpriseInfoService.selectEcardEnterpriseInfoById(ecardEnterpriseInfo.getId(), salt);
                if (ecardApiEnterpriseInfo != null) {
                    if (ecardApiEnterpriseInfo.getManagementPersonnelId().longValue() != ecardApiEcardRegistInfo.getRegistId().longValue()) {
                        ResponseModel.error("您没有编辑该企业信息的权限！");
                    }
                } else {
                    return ResponseModel.error("操作失败，未查询到该企业信息！");
                }
                flag = false;
            }
            int id = ecardEnterpriseInfoService.addEnterpriseInfo(ecardEnterpriseInfo, salt);

            //处理成员信息（新增/编辑）
            List<EcardApiMerchantPartInfo> ecardApiMerchantPartInfos = ecardEnterpriseInfo.getEcardApiMerchantPartInfos();
            if (ecardApiMerchantPartInfos.size() > 0) {
                for (EcardApiMerchantPartInfo ecardMerchantPartInfo : ecardApiMerchantPartInfos) {
                    if (!StringUtils.objIsNullOrEmpty(ecardMerchantPartInfo.getIdCard())) {
                        EcardApiMerchantPartInfo merchantPartInfo = new EcardApiMerchantPartInfo();
                        merchantPartInfo.setMerchantId(ecardMerchantPartInfo.getMerchantId());
                        merchantPartInfo.setIdCard(ecardMerchantPartInfo.getIdCard());
                        merchantPartInfo.setMerchantType("3");//商户类型：1-个人，2-商户，3-企业，4-新型农业主体
                        List<EcardApiMerchantPartInfo> partInfoList = ecardMerchantPartInfoService.selectEcardMerchantPartInfoList(merchantPartInfo, salt);
                        if (partInfoList != null && partInfoList.size() > 0) {
                            //判断是新增还是编辑
                            if (StringUtils.objIsNullOrEmpty(ecardMerchantPartInfo.getId())) {
                                return ResponseModel.error("成员信息已存在！");
                            } else {
                                if (!partInfoList.get(0).getId().equals(ecardMerchantPartInfo.getId())) {
                                    return ResponseModel.error("成员信息已存在！");
                                }
                            }
                        }
                    }

                    //查询企业人员是否存在
                    if (!StringUtils.objIsNullOrEmpty(ecardMerchantPartInfo.getId())) {
                        EcardApiMerchantPartInfo ecardApiMerchantPartInfo = ecardMerchantPartInfoService.selectEcardMerchantPartInfoById(ecardMerchantPartInfo.getId(), salt);
                        if (ecardApiMerchantPartInfo == null) {
                            //移交企业时没有修改企业成员创建人，这里不在校验企业成员创建人
                    /*if (ecardApiMerchantPartInfo.getCreatorId().longValue() != ecardApiEcardRegistInfo.getRegistId().longValue()) {
                        return ResponseModel.error("您没有编辑该企业成员的权限！");
                    }*/
                            return ResponseModel.error("成员信息不存在，请核实！");
                        }
                    }

                    //当前登录人Id
                    ecardMerchantPartInfo.setCreatorId(Long.valueOf(currentUserId));
                    ecardMerchantPartInfo.setMerchantType("3");//商户类型：1-个人，2-商户，3-企业，4-新型农业主体
                    if (flag) {//新增时取保存完企业返回的企业id，编辑时取传参的企业id
                        ecardMerchantPartInfo.setMerchantId(ecardEnterpriseInfo.getId());
                    } else {
                        ecardMerchantPartInfo.setMerchantId(entId);
                    }
                    //添加时根据企业id和商户类型判断有没有成员，没有把是否联系人字段改为是，有不操作
                    List<EcardApiMerchantPartInfo> ecardMerchantPartInfos = ecardMerchantPartInfoService.getMerchantPartList(ecardMerchantPartInfo.getMerchantId(), "3", wechatApplet.getDeptId(), salt);
                    if (ecardMerchantPartInfos.size() == 0) {
                        ecardMerchantPartInfo.setIsContacts("T");
                    }
                    ecardMerchantPartInfoService.addMerchantPartInfo(ecardMerchantPartInfo, salt);
                }
            }
            if (flag) {//只有新增企业时添加拜访任务
                //查询参数配置-拜访任务定时天数
                SysConfig config = new SysConfig();
                config.setConfigKey("ecard_merchant_task_days");
                SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
                config.setDeptId(sysDept.getDeptId());
                SysConfig sysConfig = ecardApiSysConfigService.selectConfig(config);
                int taskDays = Integer.valueOf(sysConfig.getConfigValue());//拜访任务定时天数
                /**
                 * 保存企业时新增一条拜访任务，下次回访日期默认为当前日期加拜访任务定时天数
                 */
                Date nextDay = DateUtils.getNextDay(new Date(), taskDays);
                Date endDate = DateUtils.formatDate(nextDay, DateUtils.YYYY_MM_DD);
                EcardApiMerchantTask merchantTask = new EcardApiMerchantTask();
                merchantTask.setMerchantId(ecardEnterpriseInfo.getId());
                merchantTask.setCmRegistId(ecardEnterpriseInfo.getManagementPersonnelId());
                merchantTask.setMerchantType("3");//商户类型：1-个人，2-商户，3-企业，4-新型农业主体
                merchantTask.setEndDate(endDate);
                merchantTask.setTaskSts("0");
                ecardApiMerchantTaskService.insertEcardMerchantTask(merchantTask);
            }
            return id > 0 ? ResponseModel.ok(ecardEnterpriseInfo.getId()) : ResponseModel.error("添加失败！");
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 电子名片-调用天眼查接口获取企业信息
     *
     * @author yuzhiguo
     * @date 2024/7/25 上午9:10
     */
    @PostMapping(value = "/getEnterpriseByTYC")
    @ApiOperation(value = "电子名片-调用天眼查接口获取企业信息", notes = "电子名片-调用天眼查接口获取企业信息")
    @ResponseBody
    @RsaRequest
    public ResponseModel getEnterpriseByTYC(@RequestBody String json) {
        String salt = getSalt();//盐值
        String currentUserId = getCurrentUserId();
        EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
        //接口编号
        String apiNum = ecardApiSysConfigService.selectConfigByKey("data.interfaceNum.orgBaseInfo", dept.getDeptId());
        JSONObject jsonObject = JSONObject.parseObject(json);
        String entName = jsonObject.getString("entName");//企业名称
        String entOrgCode = jsonObject.getString("entOrgCode");//企业统一机构编码
        if (StringUtils.objIsNullOrEmpty(entName)) {
            return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
        }
        EcardApiEnterpriseInfo enterpriseInfo = new EcardApiEnterpriseInfo();
        /**调用接口*/
        ResponseModel responseModel = ecardOrgInfoApiCommon.getOrgInfoByApi(userInfo, apiNum, entName, entOrgCode);
        if (responseModel.getCode() == 0) {
            JSONObject baseInfo = JSONObject.parseObject(JSON.toJSONString(responseModel.getData()));
            enterpriseInfo.setEntId(baseInfo.getString("id"));//企业id
            enterpriseInfo.setEntName(baseInfo.getString("name"));//企业名称
            enterpriseInfo.setEntLegalPerson(baseInfo.getString("legalPersonName")); //法人
            Date estiblishTime = baseInfo.get("estiblishTime") == null ? null : new Date(baseInfo.getLongValue("estiblishTime"));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String estiblishTimeStr = sdf.format(estiblishTime);
            enterpriseInfo.setEntEstiblishDate(estiblishTimeStr); //成立日期（注册日期）
            enterpriseInfo.setEntRegCapital(baseInfo.getString("regCapital"));//注册资本
            enterpriseInfo.setEntBusinessScope(baseInfo.getString("businessScope"));//经营范围
            enterpriseInfo.setEntOrgCode(baseInfo.getString("creditCode"));//统一社会信用编码
            enterpriseInfo.setEntEmployeesNum(baseInfo.getIntValue("socialStaffNum"));//参保人数（员工数量）
            enterpriseInfo.setEntAlias(baseInfo.getString("alias"));//企业简称
            enterpriseInfo.setEntRegStatus(baseInfo.getString("regStatus"));//经营状态
            enterpriseInfo.setEntPhoneNumber(baseInfo.getString("phoneNumber"));//联系方式
            //封装所有企业基本信息存到表中用于后台企业信息列表更多按钮展示企业信息
            EcardApiEnterpriseTyc ecardApiEnterpriseTyc = loadEnterpriseTyc(baseInfo);
            ecardApiEnterpriseTyc.setCreatorId(Long.valueOf(currentUserId));//创建人注册id
            //根据企业id查询企业信息，如果有更新，没有则新增
            EcardApiEnterpriseTyc apiEnterpriseTyc = ecardEnterpriseTycService.selectEcardEnterpriseTycByEntId(ecardApiEnterpriseTyc.getEntId());
            if (apiEnterpriseTyc != null){
                ecardEnterpriseTycService.updateEcardEnterpriseTycByEntId(ecardApiEnterpriseTyc);
            } else {
                ecardEnterpriseTycService.insertEcardEnterpriseTyc(ecardApiEnterpriseTyc);
            }
        } else {
            return ResponseModel.error(responseModel.getMsg());
        }
        return ResponseModel.okToJSON(enterpriseInfo);
    }

    /**
     * 组装企业基本信息
     * @param baseInfo
     * @return
     */
    public EcardApiEnterpriseTyc loadEnterpriseTyc(JSONObject baseInfo) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        EcardApiEnterpriseTyc ecardApiEnterpriseTyc = new EcardApiEnterpriseTyc();
        ecardApiEnterpriseTyc.setEntId(baseInfo.getString("id"));//企业id
        ecardApiEnterpriseTyc.setStaffNumRange(baseInfo.getString("staffNumRange"));//人员规模
        Date fromTime = baseInfo.get("fromTime") == null ? null : new Date(baseInfo.getLongValue("fromTime"));
        ecardApiEnterpriseTyc.setFromTime(fromTime == null ? null : sdf.format(fromTime)); //经营开始时间
        ecardApiEnterpriseTyc.setType(baseInfo.getInteger("type"));//法人类型，1 人 2 公司
        ecardApiEnterpriseTyc.setBondName(baseInfo.getString("bondName"));//股票名
        ecardApiEnterpriseTyc.setIsMicroEnt(baseInfo.getInteger("isMicroEnt"));//是否小微企业 0否 1是
        ecardApiEnterpriseTyc.setRegNumber(baseInfo.getString("regNumber"));//注册号
        ecardApiEnterpriseTyc.setPercentileScore(baseInfo.getInteger("percentileScore"));//万分制	企业评分
        ecardApiEnterpriseTyc.setRegCapital(baseInfo.getString("regCapital"));//注册资本
        ecardApiEnterpriseTyc.setName(baseInfo.getString("name"));//企业名
        ecardApiEnterpriseTyc.setRegInstitute(baseInfo.getString("regInstitute"));//登记机关
        ecardApiEnterpriseTyc.setRegLocation(baseInfo.getString("regLocation"));//注册地址
        ecardApiEnterpriseTyc.setIndustry(baseInfo.getString("industry"));//行业
        Date approvedTime = baseInfo.get("approvedTime") == null ? null : new Date(baseInfo.getLongValue("approvedTime"));
        ecardApiEnterpriseTyc.setApprovedTime(approvedTime == null ? null : sdf.format(approvedTime));//核准时间
        ecardApiEnterpriseTyc.setSocialStaffNum(baseInfo.getInteger("socialStaffNum"));//参保人数
        ecardApiEnterpriseTyc.setTags(baseInfo.getString("tags"));//企业标签
        ecardApiEnterpriseTyc.setTaxNumber(baseInfo.getString("taxNumber"));//纳税人识别号
        ecardApiEnterpriseTyc.setBusinessScope(baseInfo.getString("businessScope"));//经营范围
        ecardApiEnterpriseTyc.setAlias(baseInfo.getString("alias"));//简称
        ecardApiEnterpriseTyc.setOrgNumber(baseInfo.getString("orgNumber"));//组织机构代码
        ecardApiEnterpriseTyc.setRegStatus(baseInfo.getString("regStatus"));//企业状态
        Date estiblishTime = baseInfo.get("estiblishTime") == null ? null : new Date(baseInfo.getLongValue("estiblishTime"));
        ecardApiEnterpriseTyc.setEstiblishTime(estiblishTime == null ? null : sdf.format(estiblishTime));//成立日期
        Date updateTimes = baseInfo.get("updateTimes") == null ? null : new Date(baseInfo.getLongValue("updateTimes"));
        ecardApiEnterpriseTyc.setUpdateTimes(updateTimes == null ? null : sdf.format(updateTimes));//更新时间
        ecardApiEnterpriseTyc.setBondType(baseInfo.getString("bondType"));//股票类型
        ecardApiEnterpriseTyc.setLegalPersonName(baseInfo.getString("legalPersonName"));//法人
        Date toTime = StringUtils.objIsNullOrEmpty(baseInfo.get("toTime")) ? null : new Date(baseInfo.getLongValue("toTime"));
        ecardApiEnterpriseTyc.setToTime(toTime == null ? null : sdf.format(toTime));//经营结束时间
        ecardApiEnterpriseTyc.setActualCapital(baseInfo.getString("actualCapital"));//实收注册资金
        ecardApiEnterpriseTyc.setCompanyOrgType(baseInfo.getString("companyOrgType"));//企业类型
        ecardApiEnterpriseTyc.setBase(baseInfo.getString("base"));//省份简称
        ecardApiEnterpriseTyc.setCreditCode(baseInfo.getString("creditCode"));//统一社会信用代码
        ecardApiEnterpriseTyc.setBondNum(baseInfo.getString("bondNum"));//股票号
        ecardApiEnterpriseTyc.setRegCapitalCurrency(baseInfo.getString("regCapitalCurrency"));//注册资本币种：人民币、美元、欧元等
        ecardApiEnterpriseTyc.setActualCapitalCurrency(baseInfo.getString("actualCapitalCurrency"));//实收注册资本币种：人民币、美元、欧元等
        Date revokeDate = StringUtils.objIsNullOrEmpty(baseInfo.get("revokeDate")) ? null : new Date(baseInfo.getLongValue("revokeDate"));
        ecardApiEnterpriseTyc.setRevokeDate(revokeDate == null ? null : sdf.format(revokeDate));//吊销日期
        ecardApiEnterpriseTyc.setRevokeReason(baseInfo.getString("revokeReason"));//吊销原因
        Date cancelDate = StringUtils.objIsNullOrEmpty(baseInfo.get("cancelDate")) ? null : new Date(baseInfo.getLongValue("cancelDate"));
        ecardApiEnterpriseTyc.setCancelDate(cancelDate == null ? null : sdf.format(cancelDate));//注销日期
        ecardApiEnterpriseTyc.setCancelReason(baseInfo.getString("cancelReason")); //注销原因
        ecardApiEnterpriseTyc.setCity(baseInfo.getString("city"));//市
        ecardApiEnterpriseTyc.setDistrict(baseInfo.getString("district"));//区
        return ecardApiEnterpriseTyc;
    }

    /**
     * 电子名片-调用天眼查接口模糊查询获取企业列表
     *
     * @author yuzhiguo
     * @date 2024/8/5 上午10:51
     */
    @PostMapping(value = "/getLikeEnterpriseByTYC")
    @ApiOperation(value = "电子名片-调用天眼查接口模糊查询获取企业列表", notes = "电子名片-调用天眼查接口模糊查询获取企业列表")
    @ResponseBody
    @RsaRequest
    public ResponseModel getLikeEnterpriseByTYC(@RequestBody String json) {
        String salt = getSalt();//盐值
        String currentUserId = getCurrentUserId();
        EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
        //接口编号
        String apiNum = ecardApiSysConfigService.selectConfigByKey("data.interfaceNum.orgVagueSearch", dept.getDeptId());
        JSONObject jsonObject = JSONObject.parseObject(json);
        String entName = jsonObject.getString("entName");//企业名称
        String entOrgCode = jsonObject.getString("entOrgCode");//企业统一机构编码
        if (StringUtils.objIsNullOrEmpty(entName)) {
            return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
        }
        List<EcardApiEnterpriseInfo> enterpriseInfoList = new ArrayList<>();
        /**调用接口*/
        ResponseModel responseModel = ecardOrgInfoApiCommon.getOrgInfoByApi(userInfo, apiNum, entName, entOrgCode);
        if (responseModel.getCode() == 0) {
            JSONObject baseInfo = JSONObject.parseObject(JSON.toJSONString(responseModel.getData()));
            //获取企业数量
            int total = baseInfo.getIntValue("total");
            if (total > 0) {
                /**获取企业信息列表数组*/
                JSONArray items = baseInfo.getJSONArray("items");
                for (int i = 0; i < items.size(); i++) {
                    EcardApiEnterpriseInfo enterpriseInfo = new EcardApiEnterpriseInfo();
                    enterpriseInfo.setEntName(items.getJSONObject(i).getString("name"));//企业名称
                    enterpriseInfo.setEntOrgCode(items.getJSONObject(i).getString("creditCode"));//统一社会信用编码
                    enterpriseInfoList.add(enterpriseInfo);
                }
            }
        } else {
            return ResponseModel.error(responseModel.getMsg());
        }
        return ResponseModel.okToJSONArray(enterpriseInfoList);
    }

    /**
     * 电子名片-根据ID修改企业状态
     *
     * @author yuzhiguo
     * @date 2024/7/22 10:36
     */
    @PostMapping(value = "/changeEnterpriseStatus")
    @ApiOperation(value = "电子名片-根据ID修改企业状态", notes = "电子名片-根据ID修改企业状态")
    @ResponseBody
    @RsaRequest(result = false)
    public ResponseModel changeEnterpriseStatus(@RequestBody String json) {
        try {
            JSONObject jsonObject = JSONObject.parseObject(json);
            Long id = jsonObject.getLong("id");
            if (StringUtils.objIsNullOrEmpty(id)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            int updateCount = ecardEnterpriseInfoService.changeEnterpriseStatus(id);
            return updateCount > 0 ? ResponseModel.ok() : ResponseModel.error("删除失败！");
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }


    /**
     * 电子名片-保存场所信息数据接口
     *
     * @author yuzhiguo
     * @date 2024/7/26 下午5:14
     */
    @PostMapping(value = "/addLocationInfo")
    @ApiOperation(value = "电子名片-保存场所信息数据接口", notes = "电子名片-保存场所信息数据接口")
    @ResponseBody
    @RsaRequest(result = false)
    public ResponseModel addLocationInfo(@RequestBody EcardApiEnterpriseLocation ecardApiEnterpriseLocation) {
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            EcardApiEcardRegistInfo ecardApiEcardRegistInfo = registInfoService.selectEcardApiEcardRegistInfoByRegistId(Long.valueOf(currentUserId), salt);
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
            //查询支行机构下的所有楼宇
            SysDept sysDept = sysDeptService.selectThirdLevelDeptByDeptId(userInfo.getDeptId());

            if (!StringUtils.isNotNull(ecardApiEnterpriseLocation.getId())) {
                //保存时校验该支行机构下是否已经有同名的楼宇
                List<EcardApiEnterpriseLocation> enterpriseLocations = enterpriseLocationService.selectEnterpriseLocationByLocationName(ecardApiEnterpriseLocation.getLocationName(), sysDept.getDeptId(), salt);
                if (enterpriseLocations.size() > 0) {
                    return ResponseModel.error("已存在同名的场所信息！");
                }
            } else {
                //编辑时校验该楼宇是否在本人名下
                EcardApiEnterpriseLocation enterpriseLocation = enterpriseLocationService.selectEcardEnterpriseLocationById(ecardApiEnterpriseLocation.getId(), salt);
                if (enterpriseLocation != null) {
                    if (enterpriseLocation.getManagementPersonnelId().longValue() != ecardApiEcardRegistInfo.getRegistId().longValue()) {
                        return ResponseModel.error("您没有编辑该楼宇信息的权限！");
                    }
                } else {
                    return ResponseModel.error("操作失败，未查询到该楼宇信息！");
                }
            }
            //当前登录人ID
            ecardApiEnterpriseLocation.setCreatorId(Long.valueOf(currentUserId));
            //管户人id
            ecardApiEnterpriseLocation.setManagementPersonnelId(Long.valueOf(currentUserId));
            //登录人机构ID
            ecardApiEnterpriseLocation.setDeptId(userInfo.getDeptId());
            int id = enterpriseLocationService.addLocationInfo(ecardApiEnterpriseLocation, salt);
            return id > 0 ? ResponseModel.ok(ecardApiEnterpriseLocation.getId()) : ResponseModel.error("添加失败！");
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 电子名片-条件查询登录人场所信息列表接口
     *
     * @author yuzhiguo
     * @date 2024/8/5 上午11:29
     */
    @PostMapping(value = "/getLocationInfoList")
    @ApiOperation(value = "电子名片-条件查询登录人场所信息列表接口", notes = "电子名片-条件查询登录人场所信息列表接口")
    @ResponseBody
    @RsaRequest
    public ResponseModel getLocationInfoList(@RequestBody String json) {
        log.info("接口请求时间-------" + DateUtils.getTime());
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
            //当前小程序id
            SysWechatApplet wechatApplet = getAppIdByDeptId(userInfo.getDeptId());
            EcardApiEcardRegistInfo ecardApiEcardRegistInfo = registInfoService.selectEcardApiEcardRegistInfoByRegistId(Long.valueOf(currentUserId), salt);
            //查询支行机构下的所有楼宇
            SysDept sysDept = sysDeptService.selectThirdLevelDeptByDeptId(userInfo.getDeptId());
            JSONObject jsonObject = JSONObject.parseObject(json);
            String locationName = jsonObject.getString("locationName");//场所名称
            int locationType = jsonObject.getInteger("locationType");//场所类型 1：楼宇
            String type = jsonObject.getString("type");//类型 1：查询企业建档时选择的楼宇列表，2：查询企业列表筛选条件选择楼宇时展示的列表
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");

            List<EcardApiEnterpriseLocation> enterpriseLocationList = new ArrayList<>();
            PageHelper.startPage(pageNum, pageSize);
            EcardApiEnterpriseLocation ecardApiEnterpriseLocation = new EcardApiEnterpriseLocation();
            ecardApiEnterpriseLocation.setLocationName(locationName);
            ecardApiEnterpriseLocation.setLocationType(locationType);

            //企业列表筛选条件选择楼宇时展示的列表，展示本支行下所有
            if ("2".equals(type)) {
                ecardApiEnterpriseLocation.setDeptId(sysDept.getDeptId());
                enterpriseLocationList = enterpriseLocationService.getLocationInfoList(ecardApiEnterpriseLocation, salt);
                //处理每一次条场所信息中的企业数量
                for (EcardApiEnterpriseLocation enterpriseLocation : enterpriseLocationList) {
                    //查询场所下的企业数量
                    EcardApiEnterpriseInfo enterpriseInfo = new EcardApiEnterpriseInfo();
                    enterpriseInfo.setEntLocationId(Integer.valueOf(String.valueOf(enterpriseLocation.getId())));
                    enterpriseInfo.setManagementPersonnelId(Long.valueOf(String.valueOf(currentUserId)));
                    enterpriseInfo.setDictDeptId(wechatApplet.getDeptId());
                    List<EcardApiEnterpriseInfo> enterpriseList = ecardEnterpriseInfoService.getMyEnterpriseList(enterpriseInfo, salt);
                    enterpriseLocation.setEntNumber(enterpriseList.size() + "");

                    //处理是否删除字段，用于小程序列表是否删除校验，0：是，1：否
                    EcardApiEnterpriseInfo enterprise = new EcardApiEnterpriseInfo();
                    enterprise.setEntLocationId(Integer.valueOf(String.valueOf(enterpriseLocation.getId())));
                    enterprise.setDictDeptId(wechatApplet.getDeptId());
                    List<EcardApiEnterpriseInfo> enterprises = ecardEnterpriseInfoService.getEnterpriseList(enterprise);
                    if (enterprises.size() > 0) {
                        enterpriseLocation.setIsDelete("0"); //是否删除校验，0是，1否
                    } else {
                        enterpriseLocation.setIsDelete("1"); //是否删除校验，0是，1否
                    }

                    //处理是否本人字段，用于小程序列表是否显示编辑按钮，0：是，1：否
                    //校验该楼宇是否在本人名下
                    if (enterpriseLocation.getManagementPersonnelId().longValue() != ecardApiEcardRegistInfo.getRegistId().longValue()) {
                        enterpriseLocation.setIsOneself("1");//否 不显示编辑按钮
                    } else {
                        enterpriseLocation.setIsOneself("0");//是 显示编辑按钮
                    }
                }
            }

            //企业建档时选择楼宇，楼宇信息列表根据参数展示
            if ("1".equals(type)) {
                SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
                //接口编号
                //电子名片企业信息是否共享楼宇 0：是，1：否
                String configValue = configService.selectConfigByKey("ecard_enterprise_location_share", dept.getDeptId());
                if ("0".equals(configValue)) {
                    //是：查询该支行下所有的楼宇列表
                    ecardApiEnterpriseLocation.setDeptId(sysDept.getDeptId());
                    enterpriseLocationList = enterpriseLocationService.getLocationInfoList(ecardApiEnterpriseLocation, salt);
                } else {
                    //否：只查本人名下的楼宇列表
                    ecardApiEnterpriseLocation.setManagementPersonnelId(Long.valueOf(currentUserId));
                    ecardApiEnterpriseLocation.setDeptId(userInfo.getDeptId());
                    enterpriseLocationList = enterpriseLocationService.getLocationInfoList(ecardApiEnterpriseLocation, salt);
                }
            }
            PageInfo pageInfo = new PageInfo(enterpriseLocationList);
            log.info("接口返回时间-------" + DateUtils.getTime());
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), enterpriseLocationList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 电子名片-条件查询场所信息列表接口
     *
     * @param: type 1登录人所在机构下全部，2法人机构下全部（针对网格管理岗位）
     * @param: search 查询条件
     * @author yuzhiguo
     * @date 2024/8/8 15:36
     */
    @PostMapping(value = "/getAllLocationInfoList")
    @ApiOperation(value = "电子名片-条件查询场所信息列表接口", notes = "电子名片-条件查询场所信息列表接口")
    @ResponseBody
    @RsaRequest
    public ResponseModel getAllLocationInfoList(@RequestBody String json) {
        log.info("接口请求时间-------" + DateUtils.getTime());
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            //查询客户经理信息
            EcardApiEcardRegistInfo ecardApiEcardRegistInfo = registInfoService.selectEcardApiEcardRegistInfoByRegistId(Long.valueOf(currentUserId), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            String type = jsonObject.getString("type");
            String search = jsonObject.getString("search");//查询条件姓名和手机号拆开
            int locationType = jsonObject.getInteger("locationType");//场所类型 1：楼宇
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");

            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
            EcardApiEnterpriseLocation enterpriseLocation = new EcardApiEnterpriseLocation();
            enterpriseLocation.setLocationName(search);
            enterpriseLocation.setLocationType(locationType);
            //当前小程序id
            SysWechatApplet wechatApplet = getAppIdByDeptId(userInfo.getDeptId());
            if (ecardApiEcardRegistInfo != null) {
                boolean postFlag = false;
                //多个岗位判断，只要有网格管理就传法人机构
                if (!StringUtils.objIsNullOrEmpty(userInfo.getExtendPostCode())) {
                    for (String extendPost : userInfo.getExtendPostCode().split(",")) {
                        if (wg.equals(extendPost)) {
                            postFlag = true;
                        }
                    }
                }
                if (roles.equals(ecardApiEcardRegistInfo.getRoles())) {
                    if ("1".equals(type) && !postFlag) {
                        enterpriseLocation.setDeptId(userInfo.getDeptId());
                    } else if (postFlag) {
                        enterpriseLocation.setDeptId(wechatApplet.getDeptId());
                    } else {
                        return ResponseModel.error("操作人岗位不正确,请联系管理员！");
                    }
                } else {
                    return ResponseModel.error("您没有查看场所列表的权限！");
                }
            } else {
                return ResponseModel.error("用户信息不存在！");
            }


            PageHelper.startPage(pageNum, pageSize);
            List<EcardApiEnterpriseLocation> enterpriseLocationList = enterpriseLocationService.getLocationInfoList(enterpriseLocation, salt);
            //处理每一次条场所信息中的企业数量
            for (EcardApiEnterpriseLocation apiEnterpriseLocation : enterpriseLocationList) {
                //查询场所下的企业数量
                EcardApiEnterpriseInfo enterpriseInfo = new EcardApiEnterpriseInfo();
                enterpriseInfo.setEntLocationId(Integer.valueOf(String.valueOf(apiEnterpriseLocation.getId())));
                enterpriseInfo.setDictDeptId(wechatApplet.getDeptId());
                List<EcardApiEnterpriseInfo> enterpriseList = ecardEnterpriseInfoService.getEnterpriseList(enterpriseInfo);
                apiEnterpriseLocation.setEntNumber(enterpriseList.size() + "");
            }
            PageInfo pageInfo = new PageInfo(enterpriseLocationList);
            log.info("接口返回时间-------" + DateUtils.getTime());
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), enterpriseLocationList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 电子名片-条件查询场所下全部的企业列表接口
     *
     * @param: search 查询条件
     * @author yuzhiguo
     * @date 2024/7/22 8:44
     */
    @PostMapping(value = "/getAllEnterpriseListByLocation")
    @ApiOperation(value = "电子名片-条件查询场所下全部的企业列表接口", notes = "电子名片-条件查询场所下全部的企业列表接口")
    @ResponseBody
    @RsaRequest
    public ResponseModel getAllEnterpriseListByLocation(@RequestBody String json) {
        log.info("接口请求时间-------" + DateUtils.getTime());
        try {
            String salt = getSalt();//盐值
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            //当前小程序id
            SysWechatApplet wechatApplet = getAppIdByDeptId(userInfo.getDeptId());

            JSONObject jsonObject = JSONObject.parseObject(json);
            String search = jsonObject.getString("search");//查询条件姓名和手机号拆开
            Integer industry = jsonObject.getInteger("industry");
            Integer entLocationId = jsonObject.getInteger("entLocationId");//楼宇id
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");

            if (StringUtils.objIsNullOrEmpty(entLocationId)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            EcardApiEnterpriseInfo ecardEnterpriseInfo = new EcardApiEnterpriseInfo();
            ecardEnterpriseInfo.setEntName(search);
            ecardEnterpriseInfo.setEntIndustry(industry);
            ecardEnterpriseInfo.setEntLocationId(entLocationId);
            ecardEnterpriseInfo.setDictDeptId(wechatApplet.getDeptId());

            PageHelper.startPage(pageNum, pageSize);
            List<EcardApiEnterpriseInfo> enterpriseList = ecardEnterpriseInfoService.getEnterpriseList(ecardEnterpriseInfo);
            PageInfo pageInfo = new PageInfo(enterpriseList);
            log.info("接口返回时间-------" + DateUtils.getTime());
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), enterpriseList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 电子名片-查询场所信息地图坐标列表接口
     *
     * @param: type 1登录人所在机构下全部，2法人机构下全部（针对网格管理岗位）
     * @author yuzhiguo
     * @date 2024/8/8 上午11:34
     */
    @PostMapping(value = "/getLocationCoordinateList")
    @ApiOperation(value = "电子名片-查询场所信息地图坐标列表接口", notes = "电子名片-查询场所信息地图坐标列表接口")
    @ResponseBody
    @RsaRequest
    public ResponseModel getLocationCoordinateList(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            JSONObject jsonObject = JSONObject.parseObject(json);
            String type = jsonObject.getString("type");
            String coordinate = jsonObject.getString("coordinate");

            SysConfig config = new SysConfig();
            config.setConfigKey("ecard_merchant_show_distance");
            SysConfig sysConfig;

            if (StringUtils.objIsNullOrEmpty(currentUserId) || StringUtils.objIsNullOrEmpty(type)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            List<EcardApiEnterpriseLocation> enterpriseLocationList;

            if ("1".equals(type)) {
                //获取当前用户的信息
                EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
                enterpriseLocationList = enterpriseLocationService.getLocationCoordinateList(Long.valueOf(currentUserId), userInfo.getDeptId());
                SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
                config.setDeptId(sysDept.getDeptId());
                sysConfig = ecardApiSysConfigService.selectConfig(config);
            } else {
                EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
                //当前小程序id
                SysWechatApplet wechatApplet = getAppIdByDeptId(userInfo.getDeptId());
                enterpriseLocationList = enterpriseLocationService.getAllLocationCoordinateList(Long.valueOf(currentUserId), wechatApplet.getDeptId());
                SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(wechatApplet.getDeptId());
                config.setDeptId(sysDept.getDeptId());
                sysConfig = ecardApiSysConfigService.selectConfig(config);
            }

            //有经纬度就计算，没有取全部
            if (coordinate != null) {
                List<EcardApiEnterpriseLocation> list = new ArrayList<>();
                //计算是否在配置的范围之内
                //定位的场所经纬度
                String place[] = coordinate.split(",");
                for (EcardApiEnterpriseLocation enterpriseLocation : enterpriseLocationList) {
                    String clockInPlace[] = enterpriseLocation.getLocationCoordinate().split(",");
                    Double distance = GeoUtil.GetDistance(Double.valueOf(clockInPlace[1]), Double.valueOf(clockInPlace[0]), Double.valueOf(place[1]), Double.valueOf(place[0]));

                    BigDecimal bigDistance = new BigDecimal(distance);
                    BigDecimal bigValue = new BigDecimal(sysConfig.getConfigValue());
                    if (bigDistance.compareTo(bigValue) <= 0) {
                        list.add(enterpriseLocation);
                    }
                }
                return ResponseModel.okToJSONArray(list);
            } else {
                return ResponseModel.okToJSONArray(enterpriseLocationList);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 校验场所能否新增企业接口
     *
     * @author yuzhiguo
     * @date 2024/8/5 下午5:06
     */
    @PostMapping(value = "/verifyLocationAddEnt")
    @ApiOperation(value = "电子名片-校验场所能否新增企业接口", notes = "电子名片-校验场所能否新增企业接口")
    @ResponseBody
    @RsaRequest(result = false)
    public ResponseModel verifyLocationAddEnt(@RequestBody String json) {
        log.info("接口请求时间-------" + DateUtils.getTime());
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
            SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
            String configValue = configService.selectConfigByKey("ecard_enterprise_location_share", dept.getDeptId());
            EcardApiEcardRegistInfo ecardApiEcardRegistInfo = registInfoService.selectEcardApiEcardRegistInfoByRegistId(Long.valueOf(currentUserId), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            String locationId = jsonObject.getString("locationId");//场所主键id
            if (StringUtils.objIsNullOrEmpty(locationId)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            //电子名片企业信息是否共享楼宇 0：是，1：否
            if (!"0".equals(configValue)) {
                //校验该楼宇是否在本人名下
                EcardApiEnterpriseLocation enterpriseLocation = enterpriseLocationService.selectEcardEnterpriseLocationById(Long.valueOf(locationId), salt);
                if (enterpriseLocation != null) {
                    if (enterpriseLocation.getManagementPersonnelId().longValue() != ecardApiEcardRegistInfo.getRegistId().longValue()) {
                        return ResponseModel.error("您没有该楼宇新增企业的权限！");
                    }
                }
            }
            log.info("接口返回时间-------" + DateUtils.getTime());
            return ResponseModel.ok();
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 计算企业坐标是否在选择场所的配置的范围内
     *
     * @author yuzhiguo
     * @date 2024/8/12 上午10:33
     */
    @PostMapping(value = "/computeEntAndLocationRadius")
    @ApiOperation(value = "电子名片-计算企业坐标是否在选择场所的配置的范围内", notes = "电子名片-计算企业坐标是否在选择场所的配置的范围内")
    @ResponseBody
    @RsaRequest(result = false)
    public ResponseModel computeEntAndLocationRadius(@RequestBody String json) {
        String salt = getSalt();//盐值
        JSONObject jsonObject = JSONObject.parseObject(json);
        String coordinate = jsonObject.getString("coordinate");//企业坐标
        Long id = jsonObject.getLong("id");//场所id
        if (StringUtils.objIsNullOrEmpty(coordinate) || StringUtils.objIsNullOrEmpty(id)) {
            return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
        }
        String currentUserId = getCurrentUserId();
        EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
        EcardApiEnterpriseLocation enterpriseLocation = enterpriseLocationService.selectEcardEnterpriseLocationById(id, salt);
        //场所的经纬度
        String clockInPlace[] = enterpriseLocation.getLocationCoordinate().split(",");
        //定位的企业经纬度
        String place[] = coordinate.split(",");
        Double distance = GeoUtil.GetDistance(Double.valueOf(clockInPlace[1]), Double.valueOf(clockInPlace[0]), Double.valueOf(place[1]), Double.valueOf(place[0]));

        SysConfig config = new SysConfig();
        config.setConfigKey("ecard_enterprise_location_distance");
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
        config.setDeptId(sysDept.getDeptId());
        SysConfig sysConfig = ecardApiSysConfigService.selectConfig(config);

        BigDecimal bigDistance = new BigDecimal(distance);
        BigDecimal bigValue = new BigDecimal(sysConfig.getConfigValue());
        System.out.println("企业和楼宇之间的距离为========================= " + bigDistance);
        if (bigDistance.compareTo(bigValue) > 0) {
            return ResponseModel.error("所选企业位置超出系统配置的距离，请重新选择！");
        } else {
            return ResponseModel.ok();
        }

    }

    /**
     * 电子名片-保存场所信息转交记录接口
     *
     * @author yuzhiguo
     * @date 2024/8/7 上午10:31
     */
    @PostMapping(value = "/addLocationTransferInfo")
    @ApiOperation(value = "电子名片-保存场所信息转交记录接口", notes = "电子名片-保存场所信息转交记录接口")
    @ResponseBody
    @RsaRequest(result = false)
    public ResponseModel addLocationTransferInfo(@RequestBody EcardApiLocationHandover ecardLocationHandover) {
        try {
            String salt = getSalt();//盐值
            String currentUserId = getCurrentUserId();
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
            EcardApiEcardRegistInfo ecardApiEcardRegistInfo = registInfoService.selectEcardApiEcardRegistInfoByRegistId(Long.valueOf(currentUserId), salt);
            //转交时校验该楼宇是否在本人名下
            EcardApiEnterpriseLocation enterpriseLocation = enterpriseLocationService.selectEcardEnterpriseLocationById(ecardLocationHandover.getLocationId(), salt);
            if (enterpriseLocation != null) {
                if (enterpriseLocation.getManagementPersonnelId().longValue() != ecardApiEcardRegistInfo.getRegistId().longValue()) {
                    return ResponseModel.error("您没有转交该楼宇信息的权限！");
                }
            }
            //当前登录人userId
            ecardLocationHandover.setTransferId(Long.valueOf(currentUserId));
            ecardLocationHandover.setTransferDeptId(userInfo.getDeptId());
            int updateCount = enterpriseLocationService.addLocationTransferInfo(ecardLocationHandover);
            return updateCount > 0 ? ResponseModel.ok() : ResponseModel.error("转交失败！");
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }


    /**
     * 电子名片-查询场所信息详情接口
     *
     * @author yuzhiguo
     * @date 2024/7/26 下午5:26
     */
    @PostMapping("/getLocationInfo")
    @ApiOperation(value = "电子名片-查询场所信息详情接口", notes = "电子名片-查询场所信息详情接口")
    @ResponseBody
    @RsaRequest
    public ResponseModel getLocationInfo(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            JSONObject jsonObject = JSONObject.parseObject(json);
            Long id = jsonObject.getLong("id");
            if (StringUtils.objIsNullOrEmpty(id)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            EcardApiEnterpriseLocation enterpriseLocation = enterpriseLocationService.selectEcardEnterpriseLocationById(id, salt);
            return ResponseModel.okToJSON(enterpriseLocation);

        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }

    /**
     * 电子名片-根据ID修改场所信息状态
     *
     * @author yuzhiguo
     * @date 2024/7/27 上午8:38
     */
    @PostMapping(value = "/changeLocationStatus")
    @ApiOperation(value = "电子名片-根据ID修改场所信息状态", notes = "电子名片-根据ID修改场所信息状态")
    @ResponseBody
    @RsaRequest(result = false)
    public ResponseModel changeLocationStatus(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            JSONObject jsonObject = JSONObject.parseObject(json);
            Long id = jsonObject.getLong("id");
            String currentUserId = getCurrentUserId();
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(currentUserId, salt);
            //当前小程序id
            SysWechatApplet wechatApplet = getAppIdByDeptId(userInfo.getDeptId());

            EcardApiEcardRegistInfo ecardApiEcardRegistInfo = registInfoService.selectEcardApiEcardRegistInfoByRegistId(Long.valueOf(currentUserId), salt);
            if (StringUtils.objIsNullOrEmpty(id)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            //删除时校验该楼宇是否在本人名下
            EcardApiEnterpriseLocation enterpriseLocation = enterpriseLocationService.selectEcardEnterpriseLocationById(id, salt);
            if (enterpriseLocation != null) {
                if (enterpriseLocation.getManagementPersonnelId().longValue() != ecardApiEcardRegistInfo.getRegistId().longValue()) {
                    return ResponseModel.error("您没有删除该楼宇信息的权限！");
                }
            }
            EcardApiEnterpriseInfo enterpriseInfo = new EcardApiEnterpriseInfo();
            enterpriseInfo.setEntLocationId(Integer.valueOf(String.valueOf(id)));
            enterpriseInfo.setDictDeptId(wechatApplet.getDeptId());
            List<EcardApiEnterpriseInfo> enterpriseList = ecardEnterpriseInfoService.getEnterpriseList(enterpriseInfo);
            if (enterpriseList.size() > 0) {
                return ResponseModel.error("该楼宇下存在企业信息，无法删除！");
            }
            int updateCount = enterpriseLocationService.changeLocationStatus(id);
            return updateCount > 0 ? ResponseModel.ok() : ResponseModel.error("删除失败！");
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败，请联系管理员！");
        }
    }


//-----------------------------------------------------------------以下为统计接口--------------------------------------------------------------------

    /**
     * 电子名片-我的企业建档拜访数量统计接口
     *
     * @author yuzhiguo
     * @date 2024/10/31 下午5:08
     */
    @PostMapping(value = "/getEntFilingVisitsStatistics")
    @ApiOperation(value = "电子名片-我的企业建档拜访数量统计接口", notes = "电子名片-我的企业建档拜访数量统计接口")
    @ResponseBody
    @RsaRequest(param = false)
    public ResponseModel getEntFilingVisitsStatistics() {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonEntObject = ecardBranchEnterpriseChartService.getEntFilingVisitsStatistics(userInfo.getUserId());//企业建档相关
            JSONObject jsonLocationObject = ecardBranchEnterpriseChartService.getEntLocationFilings(userInfo.getUserId());//楼宇建档相关
            EcardBranchEcardChart ecardChart = new EcardBranchEcardChart();
            ecardChart.setMerchantNum(jsonEntObject.getLong("entPerFilingNums"));//企业本人累计建档总数
            ecardChart.setVisitSum(jsonEntObject.getLong("entPerVisitNums"));//企业本人累计拜访总数
            ecardChart.setDoTaskSum(jsonEntObject.getLong("entPerDoVisitNums"));//企业本人超时拜访总数
            ecardChart.setUndoTaskSum(jsonEntObject.getLong("entPerUnDoVisitNums"));//企业本人超时未拜访总数
            ecardChart.setMerchantMonthNum(jsonEntObject.getLong("entPerFilingThisMonthNums"));//企业本人本月新增建档总数
            ecardChart.setMerchantLastMonthNum(jsonEntObject.getLong("entPerFilingCompareNums"));//企业本人建档较上月对比
            ecardChart.setVisitMouthSum(jsonEntObject.getLong("entPerVisitThisMonthNums"));//企业本人本月新增拜访总数
            ecardChart.setVisitLastMouthNum(jsonEntObject.getLong("entPerVisitCompareNums"));//企业本人拜访较上月对比
            if (ecardChart.getMerchantLastMonthNum() >= 0){
                ecardChart.setCompareMerchantType("1");//较上月建档类型（1：上升，2：下降）
            } else {
                ecardChart.setCompareMerchantType("2");//较上月建档类型（1：上升，2：下降）
            }
            if (ecardChart.getVisitLastMouthNum() >= 0){
                ecardChart.setCompareVisitType("1");//较上月拜访类型（1：上升，2：下降）
            } else {
                ecardChart.setCompareVisitType("2");//较上月拜访类型（1：上升，2：下降）
            }
            ecardChart.setEntLocFilingNums(jsonLocationObject.getLong("entLocFilingNums"));//企业本人楼宇累计建档总数
            ecardChart.setEntLocFilingThisMonthNums(jsonLocationObject.getLong("entLocFilingThisMonthNums"));//企业本人本月楼宇新增建档总数
            ecardChart.setEntLocFilingCompareNums(jsonLocationObject.getLong("entLocFilingCompareNums"));//企业本人楼宇建档较上月对比
            if (ecardChart.getEntLocFilingCompareNums() >= 0){
                ecardChart.setEntLocFilingType("1");//较上月楼宇建档类型（1：上升，2：下降）
            } else {
                ecardChart.setEntLocFilingType("2");//较上月楼宇建档类型（1：上升，2：下降）
            }
            return ResponseModel.okToJSON(ecardChart);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-全行企业建档拜访数量统计接口
     *
     * @author yuzhiguo
     * @date 2024/10/31 下午5:10
     */
    @PostMapping(value = "/getEntAllFilingVisitsNums")
    @ApiOperation(value = "电子名片-全行企业建档拜访数量统计接口", notes = "电子名片-全行企业建档拜访数量统计接口")
    @ResponseBody
    @RsaRequest(param = false)
    public ResponseModel getEntAllFilingVisitsNums() {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonEntObject = ecardBranchEnterpriseChartService.getEntAllFilingVisitsNums(userInfo.getDeptId());
            JSONObject jsonLocationObject = ecardBranchEnterpriseChartService.getEntAllLocationFilings(userInfo.getDeptId());
            EcardBranchEcardChart ecardChart = new EcardBranchEcardChart();
            ecardChart.setMerchantNum(jsonEntObject.getLong("entFilingNums"));//全行企业建档总数
            ecardChart.setFilingLastMonthNums(jsonEntObject.getLong("entFilingLastMonthNums"));//上月新增企业建档总数
            ecardChart.setMerchantMonthNum(jsonEntObject.getLong("entFilingThisMonthNums"));//本月新增企业建档总数
            ecardChart.setMerchantLastMonthNum(jsonEntObject.getLong("entFilingCompareNums"));//企业建档较上月对比
            ecardChart.setVisitSum(jsonEntObject.getLong("entVisitNums"));//企业拜访总次数
            ecardChart.setVisitNewLastMonthNums(jsonEntObject.getLong("entVisitLastMonthNums"));//上月新增企业拜访总数
            ecardChart.setVisitMouthSum(jsonEntObject.getLong("entVisitThisMonthNums"));//本月新增企业拜访总数
            ecardChart.setVisitLastMouthNum(jsonEntObject.getLong("entVisitCompareNums"));//企业拜访较上月对比
            if (ecardChart.getMerchantLastMonthNum() >= 0){
                ecardChart.setCompareMerchantType("1");//较上月企业建档类型（1：上升，2：下降）
            } else {
                ecardChart.setCompareMerchantType("2");//较上月企业建档类型（1：上升，2：下降）
            }
            if (ecardChart.getVisitLastMouthNum() >= 0){
                ecardChart.setCompareVisitType("1");//较上月企业拜访类型（1：上升，2：下降）
            } else {
                ecardChart.setCompareVisitType("2");//较上月企业拜访类型（1：上升，2：下降）
            }
            ecardChart.setEntLocFilingNums(jsonLocationObject.getLong("entLocFilingNums"));//全行楼宇建档总数
            ecardChart.setEntLocFilingLastMonthNums(jsonLocationObject.getLong("entLocFilingLastMonthNums"));//上月新增楼宇建档总数
            ecardChart.setEntLocFilingThisMonthNums(jsonLocationObject.getLong("entLocFilingThisMonthNums"));//本月新增楼宇建档总数
            ecardChart.setEntLocFilingCompareNums(jsonLocationObject.getLong("entLocFilingCompareNums"));//楼宇建档较上月对比
            if (ecardChart.getEntLocFilingCompareNums() >= 0){
                ecardChart.setEntLocFilingType("1");//较上月楼宇建档类型（1：上升，2：下降）
            } else {
                ecardChart.setEntLocFilingType("2");//较上月楼宇建档类型（1：上升，2：下降）
            }
            return ResponseModel.okToJSON(ecardChart);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-企业超时拜访数量统计接口
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午8:36
     */
    @PostMapping(value = "/getEntTimeoutVisitsNums")
    @ApiOperation(value = "电子名片-企业超时拜访数量统计接口", notes = "电子名片-企业超时拜访数量统计接口")
    @ResponseBody
    @RsaRequest(param = false)
    public ResponseModel getEntTimeoutVisitsNums() {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonObject = ecardBranchEnterpriseChartService.getEntTimeoutVisitsNums(userInfo.getDeptId());
            EcardBranchEcardChart ecardChart = new EcardBranchEcardChart();
            ecardChart.setDoTaskSum(jsonObject.getLong("entDoTaskNums"));//企业超时拜访总数
            ecardChart.setDoTaskLastMonthNums(jsonObject.getLong("entDoTaskLastMonthNums"));//上月新增企业超时拜访总数
            ecardChart.setDoTaskThisMonthNums(jsonObject.getLong("entDoTaskThisMonthNums"));//本月新增企业超时拜访总数
            ecardChart.setDoTaskCompareNums(jsonObject.getLong("entDoTaskCompareNums"));//企业超时拜访较上月对比
            ecardChart.setUndoTaskSum(jsonObject.getLong("entUndoTaskNums"));//企业超时未拜访总次数
            ecardChart.setUndoTaskLastMonthNums(jsonObject.getLong("entUndoTaskLastMonthNums"));//上月新增企业超时未拜访总数
            ecardChart.setUndoTaskThisMonthNums(jsonObject.getLong("entUndoTaskThisMonthNums"));//本月新增企业超时未拜访总数
            ecardChart.setUndoTaskCompareNums(jsonObject.getLong("entUndoTaskCompareNums"));//企业超时未拜访较上月对比
            if (ecardChart.getDoTaskCompareNums() >= 0){
                ecardChart.setCompareDoType("1");//较上月超时拜访类型（1：上升，2：下降）
            } else {
                ecardChart.setCompareDoType("2");//较上月超时拜访类型（1：上升，2：下降）
            }
            if (ecardChart.getUndoTaskCompareNums() >= 0){
                ecardChart.setCompareUndoType("1");//较上月超时未拜访类型（1：上升，2：下降）
            } else {
                ecardChart.setCompareUndoType("2");//较上月超时未拜访类型（1：上升，2：下降）
            }
            return ResponseModel.okToJSON(ecardChart);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-查询企业建档折线图数据接口
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午8:44
     */
    @PostMapping(value = "/getEntFilingLineChart")
    @ApiOperation(value = "电子名片-查询企业建档折线图数据接口", notes = "电子名片-查询企业建档折线图数据接口")
    @ResponseBody
    @RsaRequest(param = false)
    public ResponseModel getEntFilingLineChart() {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            List<EcardBranchEcardChart> ecardBranchEcardChartList = ecardBranchEnterpriseChartService.getEntFilingLineChartByApplet(userInfo.getDeptId());
            return ResponseModel.okToJSONArray(ecardBranchEcardChartList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-查询企业拜访柱状图数据接口
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午8:46
     */
    @PostMapping(value = "/getEntVisitLineChart")
    @ApiOperation(value = "电子名片-查询企业拜访柱状图数据接口", notes = "电子名片-查询企业拜访柱状图数据接口")
    @ResponseBody
    @RsaRequest(param = false)
    public ResponseModel getEntVisitLineChart() {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            List<EcardBranchEcardChart> ecardBranchEcardChartList = ecardBranchEnterpriseChartService.getEntVisitLineChartByApplet(userInfo.getDeptId());
            return ResponseModel.okToJSONArray(ecardBranchEcardChartList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-各机构企业建档排名接口
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午8:49
     */
    @PostMapping(value = "/getEntDeptFilingList")
    @ApiOperation(value = "电子名片-各机构企业建档排名接口", notes = "电子名片-各机构企业建档排名接口")
    @ResponseBody
    @RsaRequest(param = true, result = true)
    public ResponseModel getEntDeptFilingList(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");
            if (StringUtils.objIsNullOrEmpty(pageNum) || StringUtils.objIsNullOrEmpty(pageSize)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            EcardBranchDeptFiling ecardBranchDeptFiling = new EcardBranchDeptFiling();
            SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
            //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
            String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
            if ("0".equals(ecardMerchantIsdept)){
                ecardBranchDeptFiling.setIsServiceLine(ecardMerchantIsdept);//是
            }
            SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());//获取县级机构
            ecardBranchDeptFiling.setDeptId(sysDept.getDeptId());
            PageHelper.startPage(pageNum, pageSize);
            List<EcardBranchDeptFiling> ecardBranchDeptFilingList = ecardBranchEnterpriseChartService.getEntDeptFilingList(ecardBranchDeptFiling);
            for (EcardBranchDeptFiling branchDeptFiling : ecardBranchDeptFilingList) {
                if (branchDeptFiling.getMerchantCompareNum() >= 0){
                    branchDeptFiling.setCompareType("1");//较上月类型（1：上升，2：下降）
                } else {
                    branchDeptFiling.setCompareType("2");//较上月类型（1：上升，2：下降）
                }
            }
            PageInfo pageInfo = new PageInfo(ecardBranchDeptFilingList);
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), ecardBranchDeptFilingList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-营销人员企业建档排名接口
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午8:58
     */
    @PostMapping(value = "/getEntUserFilingList")
    @ApiOperation(value = "电子名片-营销人员企业建档排名接口", notes = "电子名片-营销人员企业建档排名接口")
    @ResponseBody
    @RsaRequest(param = true, result = true)
    public ResponseModel getEntUserFilingList(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");
            Long appQueryDeptId = jsonObject.getLong("appQueryDeptId");//小程序传参查询用的deptId
            String userName = jsonObject.getString("userName");//小程序传参查询用的营销人员姓名
            if (StringUtils.objIsNullOrEmpty(pageNum) || StringUtils.objIsNullOrEmpty(pageSize)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            EcardBranchUserFiling ecardBranchUserFiling = new EcardBranchUserFiling();
            SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
            //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
            String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
            if ("0".equals(ecardMerchantIsdept)){
                ecardBranchUserFiling.setIsServiceLine(ecardMerchantIsdept);//是
            }
            SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());//获取县级机构
            ecardBranchUserFiling.setDeptId(sysDept.getDeptId());
            ecardBranchUserFiling.setAppQueryDeptId(appQueryDeptId);
            ecardBranchUserFiling.setUserName(userName);
            PageHelper.startPage(pageNum, pageSize);
            List<EcardBranchUserFiling> ecardBranchUserFilingList = ecardBranchEnterpriseChartService.getEntUserFilingList(ecardBranchUserFiling);
            PageInfo pageInfo = new PageInfo(ecardBranchUserFilingList);
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), ecardBranchUserFilingList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-机构企业拜访次数排名接口
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午9:04
     */
    @PostMapping(value = "/getEntDeptVisitsList")
    @ApiOperation(value = "电子名片-机构企业拜访次数排名接口", notes = "电子名片-机构企业拜访次数排名接口")
    @ResponseBody
    @RsaRequest(param = true, result = true)
    public ResponseModel getEntDeptVisitsList(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");
            if (StringUtils.objIsNullOrEmpty(pageNum) || StringUtils.objIsNullOrEmpty(pageSize)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            EcardBranchDeptVisit ecardBranchDeptVisit = new EcardBranchDeptVisit();
            SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
            //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
            String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
            if ("0".equals(ecardMerchantIsdept)){
                ecardBranchDeptVisit.setIsServiceLine(ecardMerchantIsdept);//是
            }
            SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());//获取县级机构
            ecardBranchDeptVisit.setDeptId(sysDept.getDeptId());
            PageHelper.startPage(pageNum, pageSize);
            List<EcardBranchDeptVisit> ecardBranchDeptVisitList = ecardBranchEnterpriseChartService.getEntDeptVisitsList(ecardBranchDeptVisit);
            for (EcardBranchDeptVisit branchDeptVisit : ecardBranchDeptVisitList) {
                if (branchDeptVisit.getVisitCompareNum() >= 0){
                    branchDeptVisit.setCompareType("1");//较上月类型（1：上升，2：下降）
                } else {
                    branchDeptVisit.setCompareType("2");//较上月类型（1：上升，2：下降）
                }
            }
            PageInfo pageInfo = new PageInfo(ecardBranchDeptVisitList);
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), ecardBranchDeptVisitList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-营销人员企业拜访次数排名
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午9:08
     */
    @PostMapping(value = "/getEntUserVisitsList")
    @ApiOperation(value = "电子名片-营销人员企业拜访次数排名", notes = "电子名片-营销人员企业拜访次数排名")
    @ResponseBody
    @RsaRequest(param = true, result = true)
    public ResponseModel getEntUserVisitsList(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");
            Long appQueryDeptId = jsonObject.getLong("appQueryDeptId");//小程序传参查询用的deptId
            String userName = jsonObject.getString("userName");//小程序传参查询用的营销人员姓名
            if (StringUtils.objIsNullOrEmpty(pageNum) || StringUtils.objIsNullOrEmpty(pageSize)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            EcardBranchUserVisit ecardBranchUserVisit = new EcardBranchUserVisit();
            SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
            //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
            String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
            if ("0".equals(ecardMerchantIsdept)){
                ecardBranchUserVisit.setIsServiceLine(ecardMerchantIsdept);//是
            }
            SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());//获取县级机构
            ecardBranchUserVisit.setDeptId(sysDept.getDeptId());
            ecardBranchUserVisit.setAppQueryDeptId(appQueryDeptId);
            ecardBranchUserVisit.setUserName(userName);
            PageHelper.startPage(pageNum, pageSize);
            List<EcardBranchUserVisit> ecardBranchUserVisitList = ecardBranchEnterpriseChartService.getEntUserVisitsList(ecardBranchUserVisit);
            PageInfo pageInfo = new PageInfo(ecardBranchUserVisitList);
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), ecardBranchUserVisitList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-机构企业超时拜访次数排名接口
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午9:12
     */
    @PostMapping(value = "/getEntDeptDoTaskList")
    @ApiOperation(value = "电子名片-机构企业超时拜访次数排名接口", notes = "电子名片-机构企业超时拜访次数排名接口")
    @ResponseBody
    @RsaRequest(param = true, result = true)
    public ResponseModel getEntDeptDoTaskList(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");
            if (StringUtils.objIsNullOrEmpty(pageNum) || StringUtils.objIsNullOrEmpty(pageSize)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            EcardBranchDeptDoTask ecardBranchDeptDoTask = new EcardBranchDeptDoTask();
            SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
            //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
            String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
            if ("0".equals(ecardMerchantIsdept)){
                ecardBranchDeptDoTask.setIsServiceLine(ecardMerchantIsdept);//是
            }
            SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());//获取县级机构
            ecardBranchDeptDoTask.setDeptId(sysDept.getDeptId());
            PageHelper.startPage(pageNum, pageSize);
            List<EcardBranchDeptDoTask> ecardBranchDeptDoTaskList = ecardBranchEnterpriseChartService.getEntDeptDoTaskList(ecardBranchDeptDoTask);
            PageInfo pageInfo = new PageInfo(ecardBranchDeptDoTaskList);
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), ecardBranchDeptDoTaskList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-机构企业超时未拜访次数排名接口
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午9:15
     */
    @PostMapping(value = "/getEntDeptUnDoTaskList")
    @ApiOperation(value = "电子名片-机构企业超时未拜访次数排名接口", notes = "电子名片-机构企业超时未拜访次数排名接口")
    @ResponseBody
    @RsaRequest(param = true, result = true)
    public ResponseModel getEntDeptUnDoTaskList(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");
            if (StringUtils.objIsNullOrEmpty(pageNum) || StringUtils.objIsNullOrEmpty(pageSize)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            EcardBranchDeptUndoTask ecardBranchDeptUndoTask = new EcardBranchDeptUndoTask();
            SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
            //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
            String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
            if ("0".equals(ecardMerchantIsdept)){
                ecardBranchDeptUndoTask.setIsServiceLine(ecardMerchantIsdept);//是
            }
            SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());//获取县级机构
            ecardBranchDeptUndoTask.setDeptId(sysDept.getDeptId());
            PageHelper.startPage(pageNum, pageSize);
            List<EcardBranchDeptUndoTask> ecardBranchDeptUndoTaskList = ecardBranchEnterpriseChartService.getEntDeptUnDoTaskList(ecardBranchDeptUndoTask);
            PageInfo pageInfo = new PageInfo(ecardBranchDeptUndoTaskList);
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), ecardBranchDeptUndoTaskList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-营销人员企业超时拜访次数排名接口
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午9:18
     */
    @PostMapping(value = "/getEntUserDoTaskList")
    @ApiOperation(value = "电子名片-营销人员企业超时拜访次数排名接口", notes = "电子名片-营销人员企业超时拜访次数排名接口")
    @ResponseBody
    @RsaRequest(param = true, result = true)
    public ResponseModel getEntUserDoTaskList(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");
            Long appQueryDeptId = jsonObject.getLong("appQueryDeptId");//小程序传参查询用的deptId
            String userName = jsonObject.getString("userName");//小程序传参查询用的营销人员姓名
            if (StringUtils.objIsNullOrEmpty(pageNum) || StringUtils.objIsNullOrEmpty(pageSize)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            EcardBranchUserDoTask ecardBranchUserDoTask = new EcardBranchUserDoTask();
            SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
            //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
            String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
            if ("0".equals(ecardMerchantIsdept)){
                ecardBranchUserDoTask.setIsServiceLine(ecardMerchantIsdept);//是
            }
            SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());//获取县级机构
            ecardBranchUserDoTask.setDeptId(sysDept.getDeptId());
            ecardBranchUserDoTask.setAppQueryDeptId(appQueryDeptId);
            ecardBranchUserDoTask.setUserName(userName);
            PageHelper.startPage(pageNum, pageSize);
            List<EcardBranchUserDoTask> ecardBranchUserDoTaskList = ecardBranchEnterpriseChartService.getEntUserDoTaskList(ecardBranchUserDoTask);
            PageInfo pageInfo = new PageInfo(ecardBranchUserDoTaskList);
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), ecardBranchUserDoTaskList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }

    /**
     * 电子名片-营销人员企业超时未拜访次数排名接口
     *
     * @author yuzhiguo
     * @date 2024/11/1 上午9:28
     */
    @PostMapping(value = "/getEntUserUnDoTaskList")
    @ApiOperation(value = "电子名片-营销人员企业超时未拜访次数排名接口", notes = "电子名片-营销人员企业超时未拜访次数排名接口")
    @ResponseBody
    @RsaRequest(param = true, result = true)
    public ResponseModel getEntUserUnDoTaskList(@RequestBody String json) {
        try {
            String salt = getSalt();//盐值
            //获取当前用户的信息
            EcardApiUserInfo userInfo = ecardApiUserService.getUserInfo(getCurrentUserId(), salt);
            JSONObject jsonObject = JSONObject.parseObject(json);
            int pageNum = jsonObject.getInteger("pageNum");
            int pageSize = jsonObject.getInteger("pageSize");
            Long appQueryDeptId = jsonObject.getLong("appQueryDeptId");//小程序传参查询用的deptId
            String userName = jsonObject.getString("userName");//小程序传参查询用的营销人员姓名
            if (StringUtils.objIsNullOrEmpty(pageNum) || StringUtils.objIsNullOrEmpty(pageSize)) {
                return ResponseModel.error(ResultStatus.PARAMETER_MISSING);
            }
            EcardBranchUserUndoTask ecardBranchUserUndoTask = new EcardBranchUserUndoTask();
            SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());
            //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
            String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
            if ("0".equals(ecardMerchantIsdept)){
                ecardBranchUserUndoTask.setIsServiceLine(ecardMerchantIsdept);//是
            }
            SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(userInfo.getDeptId());//获取县级机构
            ecardBranchUserUndoTask.setDeptId(sysDept.getDeptId());
            ecardBranchUserUndoTask.setAppQueryDeptId(appQueryDeptId);
            ecardBranchUserUndoTask.setUserName(userName);
            PageHelper.startPage(pageNum, pageSize);
            List<EcardBranchUserUndoTask> ecardBranchUserUndoTaskList = ecardBranchEnterpriseChartService.getEntUserUnDoTaskList(ecardBranchUserUndoTask);
            PageInfo pageInfo = new PageInfo(ecardBranchUserUndoTaskList);
            return ResponseModel.okToJSONArray(pageInfo.getTotal(), ecardBranchUserUndoTaskList);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ResponseModel.error("操作失败,请联系管理员!");
        }
    }
}
